import java.util.List;

public class AdminActions {

	private AccountDBManager accountDBManager;
	private CustomerDBManager customerDBManager;
	private DepositDBManager depositDBManager;
	private PropertyDBManager propertyDBManager;
	private RankDBManager rankDBManager;
	private AdminReports adminReports;
	private DepositTypesDBManager depositTypesDBManager;
	private BalanceDBManager balanceDBManager;
	private GeneralReports generalReports;

	public AdminActions(AccountDBManager accountDBManager, CustomerDBManager customerDBManager, PropertyDBManager propertyDBManager, RankDBManager rankDBManager, GeneralReports generalReports, AdminReports adminReports, DepositTypesDBManager depositTypesDBManager, BalanceDBManager balanceDBManager, DepositDBManager depositDBManager) {
		this.accountDBManager = accountDBManager;
		this.customerDBManager = customerDBManager;
		this.propertyDBManager = propertyDBManager;
		this.rankDBManager = rankDBManager;
		this.adminReports = adminReports;
		this.generalReports = generalReports;
		this.depositTypesDBManager = depositTypesDBManager;
		this.balanceDBManager = balanceDBManager;
		this.depositDBManager = depositDBManager;
	}

	public boolean addCustomer(Customer customer, Account account) throws DBManagerException {
		boolean flag = false;

		double moneyAmount = account.getAmount();

		Long custId = customerDBManager.addCustomer(customer, moneyAmount);

		if (custId != null) {
			account.setCustId(custId);
			flag = accountDBManager.addAccount(account);
		}

		return flag;
	}

	public boolean deleteCustomer(Customer customer) throws DBManagerException {
		boolean flag = false;
		Long custId = customer.getCustId();

		if (!adminReports.getDepositsByCustId(custId).isEmpty()) {

			// Deleting existing deposits
			for (Object deposit : adminReports.getDepositsByCustId(custId)) {

				depositDBManager.drawDeposit((Deposit) deposit);
			}

			System.out.println("[AdminActions]: Deleting active deposits before deleteing Customer...");
		}

		if (accountDBManager.deleteAccount(accountDBManager.getAccountById(custId)) && customerDBManager.deleteCustomer(customer)) {
			flag = true;
		}

		return flag;
	}

	public Customer getCustomerById(long custId) throws DBManagerException {
		return customerDBManager.getCustomerById(custId);
	}

	public boolean updateCustomerbyAdminAction(Customer customer) throws DBManagerException {
		return customerDBManager.updateCustomerbyAdminAction(customer);
	}

	public Customer getCostomerByCustId(long cust_id) throws DBManagerException {

		return adminReports.getCostomerByCustId(cust_id);
	}

	public List getDepositsByCustId(long deposit_id) {

		return adminReports.getDepositsByCustId(deposit_id);
	}

	public List getListAccounts() throws DBManagerException {

		return adminReports.getListAccounts();
	}

	public List getListCustomersByType(long type) throws DBManagerException {

		return adminReports.getListCustomersByType(type);
	}

	public List getListDeposits() throws DBManagerException {

		return adminReports.getListDeposits();
	}

	public List getListDepositTypes() throws DBManagerException {

		return adminReports.getListDepositTypes();
	}

	public DepositType getListCustomers(long type) throws DBManagerException {

		return adminReports.getDepositType(type);
	}

	public List getListBalanceActionTypes() throws DBManagerException {

		return adminReports.getListBalanceActionTypes();
	}

	public List getResumeOfIcomengMoneyBalance() throws DBManagerException {

		return adminReports.getResumeOfIcomengMoneyBalance();
	}

}
